<?php

namespace app\admin\validate\order;

use app\admin\validate\Validates;

class Order extends Validates
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'ids|标识' => 'require|array',
        'id|标识' => 'require|integer|>:0',
        'food_title|菜品名称' => 'length:1,10',
        'order_number|订单号' => 'alphaDash|max:60',
        'handle|处理状态' => 'number|in:0,1,2',
        'username|收货人' => 'chsAlphaNum|max:10',
        'mobile|收货手机号码' => 'mobile',
        'address|收货详细地址' => 'require|max:50',
        'business_remarks|商家备注' => 'max:100'
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [];

    /**
     * 场景验证
     * @var []
     */
    protected $scene = [
        'delete' => ['id'],
        'destory' => ['ids'],
        'complete' => ['id'],
        'batchComplete' => ['ids']
    ];

    /**
     * 定义首页场景验证
     * @return $this
     */
    public function sceneIndex()
    {
        $handle = config('field.order.handle');
        return $this->only(['food_title','order_number','handle','username','mobile'])
            ->append('handle', 'in:'.implode(',', array_keys($handle)));
    }

    /**
     * 定义编辑场景验证
     * @return $this
     */
    public function sceneUpdate()
    {
        return $this->only(['username','mobile','address','business_remarks'])
            ->append('username', 'require')
            ->append('mobile', 'require');
    }

}
